﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="RejectionService.cs" company="DST Nexdox">
//   Copyright (c) DST Nexdox. All rights reserved.
// </copyright>
// <summary>
//   Defines the RejectionService type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Services
{
  using System;
  using BusinessEngineInterfaces;

  using Entities;

  using Exceptions;
  using ServiceInterfaces;

  public class RejectionService : IRejectionService
  {
    private readonly IRejectionEngine rejectionEngine;

    public RejectionService(IRejectionEngine rejectionEngine)
    {
      this.rejectionEngine = rejectionEngine;
    }

    public void RejectDocument(String userName, String documentId)
    {
      try
      {
        this.rejectionEngine.RejectDocument(userName, documentId);
      }
      catch (DocumentAlreadyApprovedException)
      {
        throw new DocumentAlreadyApprovedException("Document is already approved");
      }
      catch (DocumentAlreadyRejectedException)
      {
        throw new DocumentAlreadyRejectedException("Document is already rejected");
      }
      catch (Exception e)
      {
        throw new UnityException(String.Format("Unable to approve document guid {0}", documentId), e);
      }
    }

    public BatchApprovalResults RejectGrid(String username, String grid)
    {
      try
      {
        return this.rejectionEngine.RejectGrid(grid, username);
      }
      catch (Exception e)
      {
        throw new UnityException(string.Format("Unable to reject grid {0}", grid), e);
      }
    }

    public BatchApprovalResults RejectBasket(String username, String cartId)
    {
      try
      {
        return this.rejectionEngine.RejectBasket(username, cartId);
      }
      catch (Exception e)
      {
        throw new UnityException(string.Format("Unable to reject basket for {0}", cartId), e);
      }
    }
  }
}
